package com.cwt_taxi_xa;

import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.TextView;

import com.cwt_taxi_xa.protocol.MCUUtil;
import com.cwt_taxi_xa.util.AppLog;
import com.cwt_taxi_xa.util.SPUtils;

public class ActivityVolumeChannel extends CWTBaseActivity implements SeekBar.OnSeekBarChangeListener {

	final static String TAG = "ActivityFMConfig";

	SeekBar sbMain,sbMixing,sbFrontLeft,sbFrontRight,sbBackLeft,sbBackRight;
	TextView txMain,txMixing,txFrontLeft,txFrontRight,txBackLeft,txBackRight;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		openSwipeBack(true);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_volume_channel);
		AppLog.d(TAG, "onCreate");

		sbMain = (SeekBar)findViewById(R.id.sb_volume_main);
		sbMixing = (SeekBar)findViewById(R.id.sb_volume_mixing);
		sbFrontLeft = (SeekBar)findViewById(R.id.sb_volume_front_left);
		sbFrontRight = (SeekBar)findViewById(R.id.sb_volume_front_right);
		sbBackLeft = (SeekBar)findViewById(R.id.sb_volume_back_left);
		sbBackRight = (SeekBar)findViewById(R.id.sb_volume_back_right);

		txMain = (TextView)findViewById(R.id.tv_volume_main);
		txMixing = (TextView)findViewById(R.id.tv_volume_mixing);
		txFrontLeft = (TextView)findViewById(R.id.tv_volume_front_left);
		txFrontRight = (TextView)findViewById(R.id.tv_volume_front_right);
		txBackLeft = (TextView)findViewById(R.id.tv_volume_back_left);
		txBackRight = (TextView)findViewById(R.id.tv_volume_back_right);

		sbMain.setOnSeekBarChangeListener(this);
		sbMixing.setOnSeekBarChangeListener(this);
		sbFrontLeft.setOnSeekBarChangeListener(this);
		sbFrontRight.setOnSeekBarChangeListener(this);
		sbBackLeft.setOnSeekBarChangeListener(this);
		sbBackRight.setOnSeekBarChangeListener(this);

		sbMain.setMax(32);
		sbMixing.setMax(32);
		sbFrontLeft.setMax(32);
		sbFrontRight.setMax(32);
		sbBackLeft.setMax(32);
		sbBackRight.setMax(32);

		sbMain.setProgress(SPUtils.getParamInteger("volume_main",16));
		sbMixing.setProgress(SPUtils.getParamInteger("volume_mixing",16));
		sbFrontLeft.setProgress(SPUtils.getParamInteger("volume_front_left",16));
		sbFrontRight.setProgress(SPUtils.getParamInteger("volume_front_right",16));
		sbBackLeft.setProgress(SPUtils.getParamInteger("volume_back_left",16));
		sbBackRight.setProgress(SPUtils.getParamInteger("volume_back_right",16));
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		AppLog.d(TAG,"onResume");
	}
	
	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	public void setStatus(int index, boolean status) {

	}

	@Override
	public void sendMsg(int type, Object obj) {
		// TODO Auto-generated method stub
		AppLog.d(TAG,"sendMsg type:" + type);

	}


	@Override
	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

		switch (seekBar.getId()){
			case R.id.sb_volume_main:
				txMain.setText(String.valueOf(progress));
				break;
			case R.id.sb_volume_mixing:
				txMixing.setText(String.valueOf(progress));
				break;
			case R.id.sb_volume_front_left:
				txFrontLeft.setText(String.valueOf(progress));
				break;
			case R.id.sb_volume_front_right:
				txFrontRight.setText(String.valueOf(progress));
				break;
			case R.id.sb_volume_back_left:
				txBackLeft.setText(String.valueOf(progress));
				break;
			case R.id.sb_volume_back_right:
				txBackRight.setText(String.valueOf(progress));
				break;
		}
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {

	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		switch (seekBar.getId()){
			case R.id.sb_volume_main:
				SPUtils.setParam("volume_main",seekBar.getProgress());
				MCUUtil.changeVolume(1,seekBar.getProgress());
				break;
			case R.id.sb_volume_mixing:
				SPUtils.setParam("volume_mixing",seekBar.getProgress());
				MCUUtil.changeVolume(7,seekBar.getProgress());
				break;
			case R.id.sb_volume_front_left:
				SPUtils.setParam("volume_front_left",seekBar.getProgress());
				MCUUtil.changeVolume(2,seekBar.getProgress());
				break;
			case R.id.sb_volume_front_right:
				SPUtils.setParam("volume_front_right",seekBar.getProgress());
				MCUUtil.changeVolume(3,seekBar.getProgress());
				break;
			case R.id.sb_volume_back_left:
				SPUtils.setParam("volume_back_left",seekBar.getProgress());
				MCUUtil.changeVolume(4,seekBar.getProgress());
				break;
			case R.id.sb_volume_back_right:
				SPUtils.setParam("volume_back_right",seekBar.getProgress());
				MCUUtil.changeVolume(5,seekBar.getProgress());
				break;
		}

	}

}
